<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>修改用户信息</title>
    {include file="include/top"}
</head>
<body>

<div class="layui-form" lay-filter="layuiadmin-form-useradmin" id="layuiadmin-app-form-tags"
     style="padding: 20px 0 0 0;">

    <div class="layui-form-item">
        <label class="layui-form-label">角色</label>
        <div class="layui-input-inline">
            <select name="ctype" lay-filter="ctype">
                <option value="0"
                <?php if($user['ctype']==0){echo 'selected';} ?>>系统管理</option>
                <option value="1"
                <?php if($user['ctype']==1){echo 'selected';} ?>>服务商业务</option>
                <option value="2"
                <?php if($user['ctype']==2){echo 'selected';} ?>>加油站管理</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-inline">
            <input type="text" name="username" value="{$user.username}" lay-verify="required" placeholder="请输入用户名"
                   autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-inline">
            <input type="text" name="fullname" value="{$user.fullname}" lay-verify="required" placeholder="请输入用户姓名"
                   autocomplete="off" class="layui-input">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">邮箱</label>
        <div class="layui-input-inline">
            <input type="text" name="email" value="{$user.email}" lay-verify="required" placeholder="请输入用户联系邮箱"
                   autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">电话</label>
        <div class="layui-input-inline">
            <input type="text" name="phone" value="{$user.phone}" lay-verify="required" placeholder="请输入用户电话"
                   autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">地址</label>
        <div class="layui-input-inline">
            <input type="text" name="address" value="{$user.address}" lay-verify="required" placeholder="请输入用户地址"
                   autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-inline">
            <input type="text" name="password" value="" placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">操作密码</label>
        <div class="layui-input-inline">
            <input type="text" name="password2" value="" placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-inline">
            <select name="yincang">
                <option value="1"
                <?php if($user['status']==1){echo 'selected';} ?>>正常</option>
                <option value="-1"
                <?php if($user['status']==-1){echo 'selected';} ?>>失效</option>
            </select>
        </div>
    </div>
    <span id="serviceSelectDiv" style="{$user.ctype==0?'display: none;':'display: block;'}">
    <div class="layui-form-item">
        <label class="layui-form-label">权限</label>
        <div class="layui-input-inline">
            <div class="layui-btn-container">
<!--                <button type="button" class="layui-btn" lay-demotransferactive="getData">获取右侧数据</button>-->
                <button type="button" class="layui-btn" lay-demotransferactive="reload">全部清空</button>
            </div>

            <div id="selectService" class="demo-transfer"></div>
        </div>
    </div>
    </span>
    <input name="serviceIDS" type="hidden" value="{$user.serviceIDS?json_encode($user.serviceIDS):''}">
</div>

{include file="include/js"}
<script>
    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form','transfer'], function () {
        var $ = layui.$;
        var form = layui.form;
        var transfer = layui.transfer,util = layui.util;
        function getServiceIDS(){
            var getData = transfer.getData('key123'); //获取右侧数据
            $("input[name='serviceIDS']").val(JSON.stringify(getData))
        }
        $(function (){

        })
        form.on("select(ctype)",function (re){
            re = re.value
            if(re==1){
                getService();
                $("#serviceSelectDiv").show()
            }else if(re==2) {
                getGas();
                $("#serviceSelectDiv").show()
            }else {
                $("#serviceSelectDiv").hide()
            }
        })
        function getGas(){
            $.post("getServices?type=gas",function (re){
                if(re.code==0){
                    //实例调用
                    transfer.render({
                        elem: '#selectService'
                        ,data: re.data
                        ,id: 'key123' //定义唯一索引
                        ,showSearch: true
                        ,title: ['可选加油站', '已选加油站']
                        ,width:"40%"
                        ,onchange:function (){
                            getServiceIDS()
                        }
                    })
                    {if strlen($user.serviceIDS)>2}
                    transfer.reload('key123', {
                        value: {$user.serviceIDS | raw}
                    })
                    {/if}
                }else{
                    layer.msg("初始化加油站错误")
                }
            })
        }
        function getService(){
            $.post("getServices",function (re){
                if(re.code==0){
                    //实例调用
                    transfer.render({
                        elem: '#selectService'
                        ,data: re.data
                        ,id: 'key123' //定义唯一索引
                        ,showSearch: true
                        ,title: ['可选服务商', '已选服务商']
                        ,width:"40%"
                        ,onchange:function (){
                            getServiceIDS()
                        }
                    })
                    {if strlen($user.serviceIDS)>2}
                    transfer.reload('key123', {
                        value: {$user.serviceIDS | raw}
                    })
                    {/if}
                }else{
                    layer.msg("初始化服务商错误")
                }
            })
        }

        //批量办法定事件
        util.event('lay-demoTransferActive', {
            getData: function(othis){
                var getData = transfer.getData('key123'); //获取右侧数据
                layer.alert(JSON.stringify(getData));
            }
            ,reload:function(){
                //实例重载
                transfer.reload('key123', {
                   value: []
                })
                getServiceIDS()
            }
        });
    });
</script>
</body>
</html>